package com.sk.bilibili.handler;

import com.sk.bilibili.bean.Favorites;
import com.sk.bilibili.property.MinioProperty;
import com.sk.bilibili.service.FavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * @author 邵康
 * @date 2021/12/18 15:29
 */
@Component
public class FavoritesDefaultValueHandler implements PostValueHandler<Favorites> {

    // 这里的注解是插件需要的  是创建 sqlSession 需要的  再注入  XXXMapper 会死循环
    @Autowired
    @Lazy  // 采用懒加载的方式
    private FavoritesService favoritesService;
    @Autowired
    private MinioProperty minioProperty;
    private static final String DEFAULT_COVER="default/favoritesCover.png";

    @Override
    public void postHandle(Favorites favorites) {
        if(favorites.getCover()!=null)return;
        favorites.setCover(favoritesService.getVideoSetCover(favorites.getId()));
        if(favorites.getCover()==null)favorites.setCover(minioProperty.getBasePath()+DEFAULT_COVER);
    }

}
